@extends('main')

@section('tip', '修改博文')

@section('stylesheet')
    {!! Html::style('/custom/css/parsley.css') !!}
    {!! Html::style('/custom/css/select2.min.css') !!}
@endsection

@section('content')
    <div class="row">
        {!! Form::model($post, ['route'=>['post.update', $post->id], 'method'=>'PUT']) !!}
        <div class="col-md-9">
            {!! Form::label('title', '标题:', ['style'=>'margin-top:10px']) !!}
            {!! Form::text('title', $post->title, ['class'=>'form-control']) !!}

            {!! Form::label('slug', 'Slug:', ['style'=>'margin-top:10px']) !!}
            {!! Form::text('slug', $post->slug, ['class'=>'form-control']) !!}

            {!! Form::label('category_id', '分类:', ['style'=>'margin-top:10px']) !!}
            {!! Form::select('category_id', $categories, null, ['class'=>'form-control']) !!}

            {!! Form::label('tag', '标签', ['style'=>'margin-top:10px']) !!}
            {!! Form::select('tag[]', $tags, null, ['class'=>'form-control js-basic-multiple', 'multiple'=>'multiple']) !!}

            {!! Form::label('body', '内容:',['style'=>'margin-top:30px']) !!}
            {!! Form::textarea('body', $post->body, ['class'=>'form-control', 'id'=>'tinymceform']) !!}
        </div>

        <div class="col-md-3">
            <div class="well">
                <div class="row" style="padding-left:15px">
                    <dl>
                        <dt>创建日期:</dt>
                        <dd>{!! date('Y年m月d日 <\b\r> H时i分s秒', strtotime($post->created_at)) !!}</dd>
                    </dl>
                    <dl>
                        <dt>修改日期:</dt>
                        <dd>{!! date('Y年m月d日 <\b\r> H时i分s秒', strtotime($post->updated_at)) !!}</dd>
                    </dl>
                </div>
                <hr>
                <div class="row">
                    <div class="col-md-6">
                    {!! Form::submit('保存', ['class'=>'btn btn-primary btn-block']) !!}
                    </div>
                    <div class="col-md-6">
                    {!! Html::linkRoute('post.show', '取消', $post->id, ['class'=>'btn btn-danger btn-block']) !!}
                    </div>
                </div>
                <hr>
                <div class="row">
                    <div class="col-md-12">
                        {!! Html::linkRoute('post.index', '查看所有博文', null, ['class'=>'btn btn-default btn-block']) !!}
                    </div>
                </div>
                <hr>
                <div class="row">
                    <div class="col-md-12">
                        <a href="{{ route('blog.show', $post->slug) }}" class="btn btn-default btn-block">{!! url($post->slug) !!}</a>
                    </div>
                </div>
            </div>
        </div>
        {!! Form::close() !!}
    </div>
@endsection

@section('javascript')

{!! Html::script('/custom/js/parsley.min.js') !!}
{!! Html::script('/custom/js/i18n/zh-cn.js') !!}
{!! Html::script('/custom/js/select2.min.js') !!}
{!! Html::script('/custom/js/i18n/zh-CN.js') !!}
{!! Html::script('/custom/js/tinymce/tinymce.min.js') !!}

<script type="text/javascript">
    var tags = $('.js-basic-multiple').select2();
    var ids = {!! json_encode($post->tag()->getRelatedIds()) !!};
    tags.val(ids).trigger('change');

    tinymce.init({
        selector:'#tinymceform',
        plugins:'code link preview',
        language:'zh_CN'
    });
</script>

@endsection